<!DOCTYPE html>
<html lang="en" class="">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta http-equiv="Content-Language" content="en">
  <meta http-equiv="Content-Security-Policy" content="script-src 'self' http://localhost:8090 https://* 'unsafe-inline' 'unsafe-eval'">
  <link rel="stylesheet" type="text/css" href="/github-syntax-highlight.css">
  <link rel="stylesheet" type="text/css" href="/github-markdown.css">
  <style>
    .markdown-body {
      min-width: 200px;
      max-width: 790px;
      margin: 0 auto;
      padding: 30px;
    }
    #con-error {
      position: fixed;
      top: 0px;
      right: 0px;
      padding: 5px;
      background: white;
      color: red;
    }
  </style>
  <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
  <!-- <script type="text/javascript" src="https://www.mathjax.org/cdn-shutting-down/"></script> -->
  <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
    });
  </script>
  <script src="/socket.io/socket.io.js"></script>
  <script>
    var socket = io.connect('http://'+ window.location.host +'/');
    socket.on('connect', function () {
      setDisconnected(false);
      socket.on('newContent', function(newHTML) {
        document.querySelector(".markdown-body").innerHTML = newHTML;
        MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
      });
      socket.on('die', function(newHTML) {
        window.open('', '_self', '');
        window.close();

        var firefoxWarning =
        "<h1>Oops!</h1>" +
        "<h3>Firefox doesn't allow windows to self-close.</h3>" +
        "<h3>If you want the preview window to close automatically like in other browsers, go to about:config and set dom.allow_scripts_to_close_windows to true.</h3>"
        document.body.innerHTML = firefoxWarning;
      });
    });
    socket.on('disconnect', function() {
      setDisconnected(true);
    });

    try {
      eval('// If CSP is active, then this is blocked');
    } catch (e) {
      // Detected that the CSP was active (by the user's preference).
      // Drop capabilities to prevent rendered markdown from executing scripts.
      var meta = document.createElement('meta');
      meta.setAttribute('http-equiv', 'Content-Security-Policy');
      meta.setAttribute('content', "script-src 'none';");
      document.head.appendChild(meta);
    }

    function setDisconnected(isDisconnected) {
      document.getElementById('con-error').style.display =
        isDisconnected ? 'block' : 'none';
    }
  </script>
</head>
<body>
  <div class="wrapper">
    <div class="container">
      <div class="repository-with-sidebar repo-container new-discussion-timeline with-full-navigation">
        <div id="js-repo-pjax-container" class="repository-content context-loader-container">
          <div id="readme" class="boxed-group flush clearfix announce instapaper_body md">
            <article class="markdown-body"></article>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div id="con-error" style="display:none">Live preview is unavailable</div>
</body>
</html>
